﻿//--------------------------------------------------
// Create WoW.Armory.Settings Javascript Object
//--------------------------------------------------
if ("undefined" == typeof (WoW)) {
    WoW = new Object();
}

if ("undefined" == typeof (WoW.Armory)) {
    WoW.Armory = new Object();
}

if ("undefined" == typeof (WoW.Armory.Settings)) {
    WoW.Armory.Settings = new Object();
}

// --------------------------------------------------------------------
// Load Armory Settings
// --------------------------------------------------------------------
WoW.Armory.Settings.OnLoad = function() {
    Region.value = System.Gadget.Settings.readString("Region");
    Realm.value = System.Gadget.Settings.readString("Realm");
    CharName.value = System.Gadget.Settings.readString("CharName");
    Refresh.value = System.Gadget.Settings.readString("Refresh");
}

// --------------------------------------------------------------------
// Handle the Settings dialog closed event.
// event = System.Gadget.Settings.ClosingEvent argument.
// --------------------------------------------------------------------
WoW.Armory.Settings.OnClosing = function(eventArgs) {
    if (eventArgs.closeAction == eventArgs.Action.commit) {
        System.Gadget.Settings.write("Region", Region.value);
        System.Gadget.Settings.write("Realm", Realm.value);
        System.Gadget.Settings.write("CharName", CharName.value);
        System.Gadget.Settings.write("Refresh", Refresh.value);
        System.Gadget.Settings.write("WoWArmoryFirstTime", false);
    }
    else if (eventArgs.closeAction == eventArgs.Action.cancel) {
        //Do nothing
    }
}

//-----------------------------------------------
// Delegate for the settings closing event.
//-----------------------------------------------
System.Gadget.onSettingsClosing = WoW.Armory.Settings.OnClosing;